package lac.serviceuint.handler;

import java.util.HashMap;
import java.util.Map;

import lac.serviceuint.ServiceUnitContext;

public class MethodParamHandler<T> {

	private String name;
	
	private T defaultValue;

	public MethodParamHandler(String name) {
		this.name = name;
	}
	
	public MethodParamHandler(String name,T defaultValue) {
		this.name = name;
		this.defaultValue = defaultValue;
	}
	
	public T getValue() {
		Map<String,Object> map = (Map<String,Object>)ServiceUnitContext.methodParamsMapContext.get();
		if(map !=null){
			Object value = map.get(name);
			if(value!=null){
				return (T) map.get(name);
			}else{
				return defaultValue;
			}
		}else{
			return defaultValue;
		}
		
	}
	
	public void setValue(T value){
		Map<String,Object> map = (Map<String,Object>)ServiceUnitContext.methodParamsMapContext.get();
		if(map ==null){
			map = new HashMap<>();
			ServiceUnitContext.methodParamsMapContext.set(map);
		}
		map.put(name, value);
	}
	
	
}
